package gs.android.calcfeud;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.WindowManager;

public class GamePersistor extends Activity {
	public static int SCREEN_WIDTH = 0;
	public static int SCREEN_HEIGHT = 0;
	public static int DEFAULT_ORIENTATION = 0;
	public static float SCALE = 0;
	
	private GameController controller;
	private GameModel model;
	private GameView view;
	
	public int userId, levelId;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setFormat(PixelFormat.RGBA_8888);
		
		final WindowManager.LayoutParams brightness = getWindow().getAttributes();
		brightness.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
        getWindow().setAttributes(brightness);
		
		DisplayMetrics metrics = getResources().getDisplayMetrics();
		SCREEN_WIDTH = metrics.widthPixels;
		SCREEN_HEIGHT = metrics.heightPixels;
		SCALE = metrics.density;
		
		setContentView(R.layout.game);
		
		controller = new GameController(this);
		
		view = (GameView) findViewById(R.id.view);
		view.setOnTouchListener(controller);
		model = new GameModel(this);
	}
    
    @Override
    public void onPause() {
    	super.onPause();
    	controller.onPause();
    	model.onPause();
    	view.onPause();
    }
    
    @Override
    public void onResume() {
    	super.onResume();
    	controller.onResume();
    	model.onResume();
    	view.onResume();
    }
    
    public GameModel getModel() {
    	return model;
    }
    
    public GameView getView() {
    	return view;
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	return controller.onKeyDown(keyCode, event);
    }

    /*
	import android.view.Menu;
	import android.view.MenuItem;
	import android.support.v4.app.NavUtils;
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }*/
}